import Vue from 'vue'
import Router from 'vue-router'
// import Home from './views/Home.vue'
// 导入对应的组件 注意路径要找到
import Login from './components/Login.vue'
import Home from './components/Home.vue'
import Welcome from './components/Welcome.vue'
import Users from './components/user/Users.vue'
import Roles from './components/power/Roles.vue'
import Rights from './components/power/Rights.vue'
import Cate from './components/goods/Cate.vue'
Vue.use(Router)



const router=new Router({
  routes: [
    {path:"/",redirect:"/login"},
    {path:"/login",component: Login},
    // 配置welcome子路由
    {
      path:"/home",
      component: Home,
      redirect:"/welcome",
      children:[
         {path:"/welcome",component: Welcome},
         {path:"/users",component: Users},
         { path: '/rights', component: Rights },
         { path: '/roles', component: Roles },
         { path: '/categories', component: Cate },
        //  { path: '/params', component: Params },
        //  { path: '/goods', component: GoodsList },
        //  { path: '/goods/add', component: Add },
        //  { path: '/orders', component: Order },
        //  { path: '/reports', component: Report }
      ]
    },
   
    
  ]
})

// 路由导航守卫： 有些页面是要登录才可以看的   有token 登录了 没有就没有登录 就跳转到登录去先登录
router.beforeEach((to,from,next)=>{
  //  to 要去的页面  from 从哪个页面来的  next 放行 next() 直接放行  next("/login") 直接跳转到登录
  if(to.path=="/login") return next();//去登录页面 就直接放行 去
  // 其他页面都要判断有没有token
  let tokenStr=window.sessionStorage.getItem("token");//拿出token 有代表登录了 没有就肯定没有登录
  if(!tokenStr) return next("/login");//,没有就直接跳转到登录
  next();// 前面都对了 那肯定ok 就直接放行 显示页面
})

export default router


// {
    //   path: '/',
    //   name: 'home',
    //   component: Home
    // },
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (about.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
    // }